home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Demux / Demux.h < prev   
Encoding:
C/C++ Source or Header  |  2000-05-06  |  5.1 KB  |  172 lines

  1. /* 
  2.  *  demux.h 
  3.  *
  4.  *    Copyright (C) Alberto Vigata - January 2000 - ultraflask@yahoo.com
  5.  *
  6.  *  This file is part of FlasKMPEG, a free MPEG to MPEG/AVI converter
  7.  *    
  8.  *  FlasKMPEG is free software; you can redistribute it and/or modify
  9.  *  it under the terms of the GNU General Public License as published by
  10.  *  the Free Software Foundation; either version 2, or (at your option)
  11.  *  any later version.
  12.  *   
  13.  *  FlasKMPEG is distributed in the hope that it will be useful,
  14.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  *  GNU General Public License for more details.
  17.  *   
  18.  *  You should have received a copy of the GNU General Public License
  19.  *  along with GNU Make; see the file COPYING.  If not, write to
  20.  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  21.  *
  22.  */
  23.  
  24. #ifndef DEMUX_H
  25. #define DEMUX_H
  26.  
  27.  
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <math.h>
  31. #include <windows.h>
  32. #include <winbase.h>
  33. extern "C"{
  34. #include "..\FlasKMPEG.h"
  35. }
  36. #include "..\input\inputStream.h"
  37.  
  38.  
  39. #define BUFFER_SIZE 32000
  40.  
  41. #define IDCT_MMX    1
  42. #define IDCT_NORMAL    2
  43. #define IDCT_IEEE    3
  44.  
  45. #define MPEG1_CLK_REF  (i64)90000
  46. #define MPEG2_CLK_REF  (i64)27000000
  47.  
  48.  
  49.  
  50. #include "..\BitsGetter.h"
  51.  
  52. // Stream IDs
  53. #define PACK_ID                     0xBA
  54. #define PROGRAM_STREAM_MAP       0xBC
  55. #define PRIVATE_STREAM_1         0xBD
  56. #define PADDING_STREAM           0xBE
  57. #define PRIVATE_STREAM_2         0xBF
  58. #define ECM_STREAM               0xF0
  59. #define EMM_STREAM               0xF1
  60. #define PROGRAM_STREAM_DIRECTORY 0xFF
  61. #define DSMCC_STREAM             0xF2
  62. #define ITUTRECH222TYPEE_STREAM  0xF8
  63. #define SUBSTREAM_AC3            0x80
  64. #define VIDEO_STREAM             0xE0
  65. #define AUDIO_STREAM             0xC0
  66.  
  67. // MPEG2 PACK HEADER
  68. // SCRbase and SCRext
  69. //                     32 .......................................0 9.........0
  70. // [PACK_START_CODE][01---1--][--------][-----1--][--------][-----1--][-------1]
  71.  
  72. #define ZERO            (i64)0
  73. #define GET_SCRBASE(x) ( ((ui64)x[4]&0xF8)>>3  | \
  74.                           (ui64)x[3]<<5        | \
  75.                          ((ui64)x[2]&0x03)<<13 | \
  76.                          ((ui64)x[2]&0xF8)<<12 | \
  77.                           (ui64)x[1]<<20       | \
  78.                          ((ui64)x[0]&0x03)<<28 | \
  79.                           (ui64)x[0]&0x38 <<27 )
  80.  
  81. #define GET_SCREXT(x)  ( ((ui64)x[5]&0xFE)>>1     | \
  82.                          ((ui64)x[4]&0x03)<<7 )
  83.  
  84. // muxrate
  85. //      22 ......................0         stl
  86. // ... [--------][--------][------11][rrrrr---]
  87. #define GET_MPEG2MUXRATE(x) ( (ui32)x[6]<<14 | ((ui32)x[7])<<6 | ((ui32)x[8]&0x03)>>2)
  88.  
  89. #define GET_MPEG2STUFFING(x) ((x[9]&0x07)) 
  90. // MPEG1 PACK HEADER
  91. //                       SCR                                            muxrate
  92. //                       32........................................0    22.......................0
  93. // [PACK_START_CODE][0010---1][--------][-------1][--------][-------1][1-------][--------][-------1]
  94. #define GET_SCR(x)     ( ((ui64)x[4]&0xFE) >>1     | \
  95.                          ((ui64)x[3])      <<7     | \
  96.                          ((ui64)x[2]&0xFE) <<14    | \
  97.                          ((ui64)x[1])      <<22    | \
  98.                          ((ui64)x[0]&0x0E) <<29 )
  99. #define GET_MPEG1_PTS(x) (GET_SCR(x)) //they follow the same pattern
  100.  
  101. #define GET_MPEG1_MUXRATE(x) ( ((ui32)x[7]&0xFE) >>1     | \
  102.                                ((ui32)x[6])         <<7     | \
  103.                                ((ui32)x[5]&0x7F) <<15 )
  104.  
  105. // MPEG2 PES packet (first 5 bytes)
  106. //                     Packet lenght                 PTS       Header length
  107. //                     15...............0                      7......0            
  108. // [PACKET_START_CODE][--------][--------][10------][xx------][--------]
  109. #define GET_MPEG_PACKET_LENGHT(x) ( ((ui16)x[0]<<8) | (ui16)x[1] )
  110. #define GET_MPEG2_PTS_FLAGS(x) ( ((ui8)x[3]&0xC0)>>6  )
  111. // MPEG2 PES packet (optional parameters)
  112. //                         PTS                      
  113. //                         32........................................0
  114. // [PACKET_START_CODE][001x---1][--------][-------1][--------][-------1]
  115. #define GET_MPEG2_PTS(x)   ( ((ui64)x[4]&0xFE) >>1     | \
  116.                                ((ui64)x[3])      <<7     | \
  117.                              ((ui64)x[2]&0xFE) <<14    | \
  118.                              ((ui64)x[1])      <<22    | \
  119.                              ((ui64)x[0]&0x0E) <<29 )
  120.  
  121.  
  122. #define GET_UINT16(x)   ( ((ui16)x[0]<<8)|((ui16)x[1]))
  123.  
  124. class CDemux: public CBitSource
  125. {
  126. public:
  127.     int SetWorkingMode(int mode);
  128.     void StartReadLPES();
  129.     int ReadLPES(unsigned char **buffer, PESinfo *PES);
  130.     i64 GetTime();
  131.  
  132.     CDemux();
  133.     ~CDemux();
  134.  
  135.     int ReadPES(unsigned char **buffer, PESinfo *PES);
  136.  
  137.     ResetSCR();
  138.     ResetPTS();
  139.  
  140.     i64 getSCR();
  141.     i64    getPTS();
  142.  
  143.     int         isMPEG2;
  144.     ui32        muxRate;
  145.  
  146.  
  147.     bool        PTSread;
  148.     int        SetInput(char         *inputfile);
  149.     int        SetInput(CinputStream *inpStream);
  150.     int        UnSetInput();
  151.  
  152.     
  153.     bool                EndOfFile;
  154.  
  155. protected:
  156.     ui8    inbuf[65536];
  157.     i64     SCR, SCRbase,SCRext, PTS;
  158.     int     AlignPack();
  159.     CinputStream *inp,*myInputStream;
  160.  
  161. private:
  162.     bool firstTime;
  163.      i64 delta;
  164.      i64 lastSCR;
  165.     ui32 lastPackBytes;
  166.     ui32 lastMuxRate;
  167. };
  168.  
  169.  
  170.  
  171.  
  172. #endif  DEMUX_H